unit uPauseScreen;

interface

uses
  zglHeader,
  uGUI,
  uGlobal;

type

  TPauseScreen = class
    protected
      font : zglPFont;
      gui : TGUIManager;
      camera : zglPCamera2d;
      global : TGlobal;
      x,y:single;
      texture : zglPTexture;
      //btn_restart : TButton;
      //btn_toMenu : TButton;
    public
      constructor Create(_global : TGlobal; _texture : zglPTexture);
      procedure process;
      procedure draw;
      destructor Destroy; override;
  end;


  TExitBtn = class(TButton)
    private
      global : TGlobal;
    public
      constructor Create(const x0, y0 : single; w0, h0 : word; layer0 : byte; font0 : zglPFont;
                        text0 : string; gui0 : TGUIManager;  _global : TGlobal);
      procedure onClick(data : pointer); override;
  end;
    TAgainBtn = class(TButton)
    private
      global : TGlobal;
    public
      constructor Create(const x0, y0 : single; w0, h0 : word; layer0 : byte; font0 : zglPFont;
                        text0 : string; gui0 : TGUIManager; _global : TGlobal);
      procedure onClick(data : pointer); override;
  end;
  TMenuExitBtn = class(TButton)
    private
      global : TGlobal;
    public
      constructor Create(const x0, y0 : single; w0, h0 : word; layer0 : byte; font0 : zglPFont;
                        text0 : string; gui0 : TGUIManager; _global : TGlobal);
      procedure onClick(data : pointer); override;
  end;


implementation

constructor TPauseScreen.Create(_global : TGlobal; _texture : zglPTexture);
begin
  global := _global;
  camera := cam2d_get;
  x:=camera.X+640/4;
  y:=camera.Y+480/4;
  gui := TGUImanager.Create;
  font := font_LoadFromFile(FontPath + 'standard 07_57-Regular-18pt.zfi');
  gui.elementList.Add(TAgainBtn.Create(x + 85, y + 125, 50, 10, 0, font,'Restart(R)', gui, global));
  gui.elementList.Add(TMenuExitBtn.Create(x + 205, y + 125, 50, 10, 0, font, 'Menu', gui, global));
  //gui.elementList.Add(TExitBtn.Create(x + 135, y + 180, 50, 10, 0, font, 'Exit', gui,global));
  gui.displayLayer := 0;
  texture := _texture;
end;

procedure TPauseScreen.process;
begin
  if key_press(K_R) then
  begin
    //TButton(TAgainBtn).onClick(Self);
    global.restartGame:=true;
    global.paused:=false;
  end;
  //if key_press(K_M) then btn_toMenu.onClick(Self);
  
  
  gui.process;
end;

destructor TPauseScreen.Destroy;
begin
gui.Free;
end;

procedure TPauseScreen.draw;
begin
  //pr2d_rect(x+80,y+80+60,160,60,$000000,255,PR2d_FILL);
  ssprite2d_draw(texture, x + 80, y + 80, 160, 60, 0);
  gui.draw;
end;

{ TAgainBtn }

constructor TAgainBtn.Create(const x0, y0: single; w0, h0: word; layer0: byte;
  font0: zglPFont; text0: string; gui0: TGUIManager; _global: TGlobal);
begin
  inherited Create(x0, y0, w0, h0, layer0, font0, text0, gui0);
  global := _global;
end;

procedure TAgainBtn.onClick(data: pointer);
begin
  global.restartGame:=true;
  global.paused:=false;
end;

constructor TExitBtn.Create(const x0, y0 : single; w0, h0 : word; layer0 : byte; font0 : zglPFont;
                        text0 : string; gui0 : TGUIManager;  _global : TGlobal);
begin
  inherited Create(x0, y0, w0, h0, layer0, font0, text0, gui0);
  global:=_global;
end;
procedure TExitBtn.onClick(data: Pointer);
begin
  global.paused:=false;
  zgl_Exit;
end;


{ TMenuExitBtn }

constructor TMenuExitBtn.Create(const x0, y0: single; w0, h0: word;
  layer0: byte; font0: zglPFont; text0: string; gui0: TGUIManager;
  _global: TGlobal);
begin
  inherited Create(x0, y0, w0, h0, layer0, font0, text0, gui0);
  global := _global;
end;

procedure TMenuExitBtn.onClick(data: pointer);
var
camera : zglPCamera2d;
begin
  global.paused:=false;
  global.restartGame:=true;
  global.mode:=mmenu;
  camera:=cam2d_get;
  camera.X:=-640/4;
  camera.Y:=-480/4;
  cam2d_set(camera);
end;

end.
